package com.iseastar.guojiang.util;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.DPoint;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.CoordinateConverter;
import com.iseastar.guojiang.BeeApplication;

/**
 * Created by joker on 2018/5/2.
 */
public class LocationUtils {
    /**
     * 高德转百度
     *
     * @param aMapLocation
     * @return
     */
    public static LatLng locationConvert(AMapLocation aMapLocation) {
        if (aMapLocation == null) {
            return null;
        }
        CoordinateConverter converter = new CoordinateConverter();
        // CoordType.GPS 待转换坐标类型
        converter.from(CoordinateConverter.CoordType.COMMON);
        LatLng latLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
// sourceLatLng待转换坐标点 DPoint类型
        LatLng point = null;
        try {
            converter.coord(latLng);
            point = converter.convert();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return point;
    }

    /**
     * 百度转高德
     *
     * @param lat
     * @param lng
     * @return
     */
    public static DPoint convertToGaoDeLocation(double lat, double lng) {
        com.amap.api.location.CoordinateConverter converter = new com.amap.api.location.CoordinateConverter(BeeApplication.getContext());
        // CoordType.GPS 待转换坐标类型
        converter.from(com.amap.api.location.CoordinateConverter.CoordType.BAIDU);
        // sourceLatLng待转换坐标点 LatLng类型
        DPoint dPoint = new DPoint();
        dPoint.setLatitude(lat);
        dPoint.setLongitude(lng);
        DPoint point = null;
        try {
            converter.coord(dPoint);
            point = converter.convert();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return point;
    }
}
